package com.ark.controller.game;

import com.ark.common.domain.entity.game.GameInfo;
import com.ark.common.domain.model.GameBody;
import com.ark.common.response.Result;
import com.ark.service.cache.GlobalGameConfigCache;
import com.ark.service.service.GameInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/api/gameInfo")
public class GameInfoController {

    @Resource
    private GameInfoService gameInfoService;
    @Resource
    private GlobalGameConfigCache globalGameConfigCache;

    /**
     * 获取游戏账号消息
     * @param gameInfo 搜索条件
     * @param pageNum 页数
     * @param pageSize 页数大小
     */
    @GetMapping("/list")
    public Result list(GameInfo gameInfo,@RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize){
        Page<GameInfo> page=new Page<>(pageNum, pageSize);
        IPage<GameInfo> pageInfo=gameInfoService.selectList(page,gameInfo);
        return Result.success(pageInfo);
    }

    /**
     * 查询游戏分类账号
     */
    @GetMapping("/categoryList")
    public Result categoryList(){
        return Result.success(gameInfoService.categoryList());
    }

    /**
     * 添加游戏账号
     * @param gameInfo 游戏信息
     */
    @PostMapping
    public Result addGameInfo(@Valid @RequestBody GameBody gameBody){

        return gameInfoService.insertGameInfo(gameBody.getGameInfo(), gameBody.getEmail())?Result.success():Result.error();
    }


    @PutMapping
    public Result updateGameInfo(GameInfo gameInfo){
        return Result.success();
    }

    @DeleteMapping("/{gameInfoIds}")
    public Result deleteGameInfo(@PathVariable Long[] gameInfoIds){
        return Result.success();
    }

    @GetMapping("/getGameInfo")
    public Result getGameInfo(){
        Map<String,Object> info=new HashMap<>();
        GameInfo gameInfo = gameInfoService.getGameInfo();
        Object gameConfig = globalGameConfigCache.getGameConfig();
        info.put("gameInfo",gameInfo);
        info.put("gameConfig",gameConfig);
        return Result.success(info);
    }
}
